package com.simba.server.commands.impl.del;

import com.simba.common.command.ICommand;
import com.simba.common.database.DbOperator;

public class TruncateTableCmd implements ICommand
{
	public static final String NAME = "TruncateTableCmd";
	private String sql = "truncate table ";
	private final String tableName;

	public TruncateTableCmd(String tableName)
	{
		this.tableName = tableName;
	}

	@Override
	public String getName()
	{
		return TruncateTableCmd.NAME;
	}

	@Override
	public Boolean run(Object params)
	{
		Boolean ret = false;

		if (!(params instanceof DbOperator))
		{
			return ret;
		}

		try
		{
			DbOperator dbOperator = (DbOperator) params;

			this.sql += this.tableName + ";";
			dbOperator.prepareStatement(this.sql);

			int rs = dbOperator.executeUpdate();
			if (rs >= 0)
			{
				ret = true;
			}
		}
		catch (Exception ex)
		{
			ret = false;
		}

		return ret;
	}

}
